package com.shop.cloud.controller.hongfu;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.shop.cloud.common.mybatis.BaseController;
import com.shop.cloud.domain.hongfu.GoodsOrder;
import com.shop.cloud.filter.CurrentUserId;
import com.shop.cloud.model.response.ObjectDataResponse;
import com.shop.cloud.service.hongfu.IGoodsOrderService;
import com.shop.cloud.util.Page;

import io.swagger.annotations.ApiOperation;

/**
 * 用户订单管理
 * @author Yan Weiwei
 *
 */
@RestController	
@RequestMapping(value = "api")
public class UserOrderController extends BaseController {

	@Autowired
	private IGoodsOrderService goodsOrderService;
	
	@ApiOperation(value = "用户下单", notes = "用户下单")
	@RequestMapping(value = "/placeAnOrder", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<Integer> placeAnOrder(@CurrentUserId Long userId, @RequestBody GoodsOrder goodsOrder){
		
		goodsOrder.setUserId(userId);
		int resultData = goodsOrderService.handleplaceAnOrder(goodsOrder);
		
		return new ObjectDataResponse<Integer>(resultData);
	}
	
	@ApiOperation(value = "获取我的订单列表", notes = "获取我的订单列表")
	@RequestMapping(value = "/getMyOrderList", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<Page<GoodsOrder>> getMyOrderList(@CurrentUserId Long userId, @RequestBody GoodsOrder goodsOrder){
		
		goodsOrder.setUserId(userId);
		goodsOrder.setOrderBy("GOODS_ORDER.create_time DESC");
		Page<GoodsOrder> data = goodsOrderService.handleOrderList(goodsOrder);
		
		return new ObjectDataResponse<Page<GoodsOrder>>(data);
	}
	
	@ApiOperation(value = "修改我的订单状态", notes = "修改我的订单状态")
	@RequestMapping(value = "/modifyMyOrder", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<Integer> modifyMyOrder(@RequestBody GoodsOrder goodsOrder){
		
		int data = goodsOrderService.handleOrderStatus(goodsOrder);
		
		return new ObjectDataResponse<Integer>(data);
	}
	
	@ApiOperation(value = "获取订单详情", notes = "获取订单详情")
	@RequestMapping(value = "/getMyOrderByOne", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<GoodsOrder> getMyOrderByOne(@RequestBody GoodsOrder goodsOrder){
		
		GoodsOrder data = goodsOrderService.handleOrderDetail(goodsOrder);
		
		return new ObjectDataResponse<GoodsOrder>(data);
	}
	
}
